/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sapra.abc;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.sapra.core.DBManager;
import org.sapra.dao.Carrera;

/**
 *
 * @author ppratsc
 */
public class dCarrera {

    public static List<Carrera> getCarreras(int opc, String nuevo) {
        List<Carrera> resp = null;
        String sql = "SELECT * FROM carrera";
        if(opc==0)
            sql += " ORDER BY nombre";
        else
            sql += " where nombre='"+nuevo+"'";

        try {
            // Busca las Universidades
            resp = DBManager.getQuery(Carrera.class,sql);
        } catch (Exception ex) {
            Logger.getLogger(dCarrera.class.getName()).log(Level.SEVERE, null, ex);
        }
        return resp;
    }


       static int NuevoCarrera(String string){
        int resp=0;

        String sql= "INSERT INTO carrera (nombre) VALUES (";
        sql+="'"+string+"'";
        sql+=")";
         try {
            resp = DBManager.Update(sql);
        } catch (Exception ex) {
            Logger.getLogger(dCarrera.class.getName()).log(Level.SEVERE, null, ex);
        }

        return resp;
    }

       public static int editarCarrera(Carrera cr,String nombre){
        int resp=0;
        String sql = "UPDATE carrera SET ";
        sql += "nombre = '" + nombre + "'";
        sql += " WHERE carreraId = " + cr.getCarreraId();
        try {
            resp = DBManager.Update(sql);
        } catch (Exception ex) {
            Logger.getLogger(dCarrera.class.getName()).log(Level.SEVERE, null, ex);
        }

        return resp;
    }

           static int borrarCarrera(Carrera cr){
        int resp=0;
        String sql = "DELETE FROM carrera WHERE carreraId = " + cr.getCarreraId();
        try {
            resp = DBManager.Update(sql);
        } catch (Exception ex) {
            Logger.getLogger(dCarrera.class.getName()).log(Level.SEVERE, null, ex);
        }
        return resp;


    }

public static Carrera getCarrera(int opc){
        Carrera resp = null;

        String sql = "SELECT ";
        sql += "nombre ";
        sql += " FROM ";
        sql += "carrera";
        sql += " WHERE ";
        sql += " carreraId = " + opc;

        List<Carrera> crs;
        try {
            DBManager db=new DBManager();
            // Busca la universidad en la base de datos
            crs = db.getQuery(Carrera.class,sql);
            db=null;
            resp=new Carrera();
            resp=crs.get(0);
        } catch (Exception ex) {
            Logger.getLogger(dCarrera.class.getName()).log(Level.SEVERE, null, ex);
            return resp;
        }

        return resp;
    }


}
